package com.xinqi.modules.exam.task.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.exam.task.client.AsyncTaskProcessLogClient;
import com.xinqi.modules.exam.task.dto.req.AsyncTaskProcessLogQueryDTO;
import com.xinqi.modules.exam.task.dto.rsp.AsyncTaskProcessLogResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 异步任务处理日志降级处理
 *
 * @author: linkai
 * @date: 2023/07/08
 */
@Slf4j
@Component
public class AsyncTaskProcessLogFallbackFactory implements FallbackFactory<AsyncTaskProcessLogClient> {

    @Override
    public AsyncTaskProcessLogClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new AsyncTaskProcessLogClient() {
            @Override
            public R<PageInfo<AsyncTaskProcessLogResultDTO>> page(AsyncTaskProcessLogQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<AsyncTaskProcessLogResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

        };
    }
}
